//
//  HMToolBarView.swift
//  WeiBo
//
//  Created by 李立达 on 15/12/10.
//  Copyright © 2015年 heima11. All rights reserved.
//

import UIKit
import SnapKit

class HMToolBarView: UIView {
    
    
    var retweetButton: UIButton?
    var commentButton: UIButton?
    var unlikeButton: UIButton?
    
    
    var toolBarModel : HMstatusModel? {
        didSet{
            retweetButton?.setTitle(toolBarModel?.retweetCountStr, forState: UIControlState.Normal)
            commentButton?.setTitle(toolBarModel?.commentCountStr, forState: UIControlState.Normal)
            unlikeButton?.setTitle(toolBarModel?.attitudeCountStr, forState: UIControlState.Normal)
        }
    }
   
    
    
   override init(frame: CGRect) {
        
        super.init(frame: frame)
        steupUI()
    }

   required init?(coder aDecoder: NSCoder) {
       fatalError("init(coder:) has not been implemented")
   }
    
     private  func steupUI() {
        retweetButton = addbutton("转发", imageName: "timeline_icon_retweet")
        commentButton = addbutton("评论", imageName: "timeline_icon_comment")
        unlikeButton = addbutton("赞", imageName: "timeline_icon_unlike")
          
        let line1 = addline()
        let line2 = addline()
        
        retweetButton?.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(self)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.width.equalTo(commentButton!)
        }
        commentButton?.snp_makeConstraints { (make) -> Void in
                make.leading.equalTo(retweetButton!.snp_trailing)
                make.top.equalTo(self)
                make.bottom.equalTo(self)
                make.width.equalTo(unlikeButton!)
        }
        unlikeButton?.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(self)
            make.top.equalTo(self)
            make.trailing.equalTo(self)
                make.leading.equalTo(commentButton!.snp_trailing)
        }
      
        
        line1.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(retweetButton!.snp_trailing)
            make.centerY.equalTo(self)
        }
        
        line2.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(commentButton!.snp_trailing)
            make.centerY.equalTo(self)
        }
    }
    
  private  func addbutton(title: String ,imageName : String )-> UIButton {
        let button = UIButton()
        button.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        button.setTitle(title, forState: UIControlState.Normal)
        button.setTitleColor(UIColor.grayColor(), forState: UIControlState.Normal)
        button.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Highlighted)
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: UIControlState.Highlighted)
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: UIControlState.Normal)
        button.titleLabel?.font = UIFont.systemFontOfSize(15)
        addSubview(button)
        return button
    }
    
    func addline ()-> UIImageView {
    
        let lineimagev = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
        
        addSubview(lineimagev)
        return lineimagev
    }
}
